package com.example.learnspring.controller;

import com.example.learnspring.entity.Dept;
import com.example.learnspring.entity.Result;
import com.example.learnspring.service.DeptService;
import com.example.learnspring.service.DeptServiceImpl;
import jakarta.annotation.Resources;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RequestMapping("/depts")
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;


    @GetMapping
    public Result getAll(){
        List<Dept> depts = deptService.getDepts();
        return Result.success(depts);
    }
    @DeleteMapping
    public Result deleteDeptById(Integer id){
        deptService.deleteDeptById(id);
        return Result.success();
    }

    @PostMapping
    public Result addDept(@RequestBody Dept dept){
        deptService.addDept(dept);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getDeptById(@PathVariable Integer id){
        Dept dept = deptService.getDeptById(id);
        return Result.success(dept);
    }

    @PutMapping
    public Result update(@RequestBody Dept dept){
        deptService.updateDept(dept);
        return Result.success();
    }
}
